'use strict'

class collect {

  constructor () {
    //param默认就是/:id，若要改变路由，则可以设置此属性，比如设置为/:name
    //this.param = '/:id'
  }
  async get(c) {
    let sqltext = `SELECT * FROM mycollection WHERE open_Id=$1`;
    let r = await c.service.psql.query(sqltext,[c.box.user.openid]);
    console.log(r.rows);
    c.send(JSON.stringify(r.rows));
  }
  async list(c){
    let sqltext = `SELECT * FROM mycollection WHERE open_Id=$1`;
    let r = await c.service.psql.query(sqltext,[c.box.user.openid]);
    console.log(r.rows);
    c.send(JSON.stringify(r.rows));
  }
  async delete (c) {
    let sqltext = `DELETE FROM mycollection WHERE name=$1 and open_Id=$2`;
    let r = await c.service.psql.query(sqltext,[c.body.name,c.box.user.openid]);
    console.log(r.rows);
    c.send(JSON.stringify(r.rows));
  }

}

module.exports = collect